package work;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class test5 {
private static int tot=0;
public static void main(String[] args) {
	ExecutorService es=Executors.newFixedThreadPool(10);
	for(int i=1;i<=10;i++){
		int start=(i-1)*10+1;
		int end=i*10;
		es.execute(new sumtot(start,end));
	}
	es.shutdown();
	try {
        es.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    System.out.println("总计： " + tot);
	}
	static class sumtot implements Runnable{
	private int start;
	private int end;
	public  sumtot(int start,int end){
		this.start=start;
		this.end=end;
	}
		@Override
        public void run() {
		int sum=0;
		for(int i=start;i<=end;i++){
			sum+=i;
		}
		synchronized (test5.class) {
			tot+=sum;
		}
	}
}
}
